import {
  Column,
  Entity,
  Generated,
  ManyToMany,
  OneToMany,
  PrimaryColumn,
  PrimaryGeneratedColumn,
} from 'typeorm';
import { User } from './user.entity';
import { BaseEntity } from '../entities/base.entity';
import { RoleMenu } from './role-menu.entity';
import * as crypto from 'crypto';

@Entity('role')
export class Role extends BaseEntity {
  constructor() {
    super();
    this.id = crypto.randomBytes(8).toString('hex'); // 生成一个8字节（16个十六进制字符）的随机字符串作为id
  }
  // 自增唯一主键
  @PrimaryColumn({ length: 225 })
  id: string;

  // 角色名
  @Column()
  roleName: string;

  // 角色名
  @Column()
  roleCode: string;

  // 角色名
  @Column()
  remark: string;

  @OneToMany((type) => RoleMenu, (roleMenu) => roleMenu.roleId)
  roleMenus: RoleMenu[];

  @ManyToMany(() => User, (user) => user.roles)
  users: User[];
}
